package com.echo.gateway.config;

import com.echo.kernel.jwt.properties.JwtProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;

import java.nio.charset.StandardCharsets;

/**
 * @author chentl
 * @version V1.0
 * @Project JwtTokenConfig
 * @Title JwtTokenConfig.java
 * @Description JWT token管理配置
 * @Package com.echo.auth.config
 * @date 2019/10/25 13:06
 * @Copyright: 上海顺益信息科技有限公司 All rights reserved.
 */
@Configuration
public class JwtTokenConfig {


    @Autowired
    private JwtProperties jwtProperties;


    @Bean
    public TokenStore jwtTokenStore() {
        return new JwtTokenStore(jwtAccessTokenConverter());
    }

    @Bean
    public JwtAccessTokenConverter jwtAccessTokenConverter() {
        JwtAccessTokenConverter accessTokenConverter = new JwtAccessTokenConverter();
        accessTokenConverter.setSigningKey(new String(jwtProperties.getSecret().getBytes(StandardCharsets.UTF_8)));
        return accessTokenConverter;
    }

}